<?php

namespace App\Http\Controllers\Help;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;


class HelpController extends Controller
{

    /**
     *index
     */
    public function index()
    {
		$data = DB::table("help")->orderBy("id","desc")->get();
		return view("help.index",["list" => $data]);
    }

    /*
	*添加问题页
	*/
	public function add(){
		
		return view("help.add");
	}

/*
	* 存储
*/

	public function create(Request $request){
		$data = $request->input();
		array_shift($data);
		$data['date'] = date("Y-m-d H:i:s");
		$re = DB::table("help")->insert($data);
		if($re){
				return redirect("help/index");
		}else{
				return back()->with('add_error','操作失败');
		}
	}
    /**
     * edit--update 
     */
    public function edit(Request $request)
    {
        $id = $request->input("id");
		$data = DB::table("help")->where("id",$id)->get();
		//dd($data);
		return view("help.edit",["data" => $data[0]]);
    }

    /**
     * delete
     */
    public function destroy(Request $request)
    {
        $id = $request->input("id");
		//dd($id);
		$re = DB::table("help")->where("id",$id)->delete();
		if($re){
			return redirect("help/index");
		}else{
			return back()->with('delete_error','操作失败');
		}
    }
	/**
		*更新储存
	**/
	public function store(Request $request){
		$data = $request->input();
		array_shift($data);
		$id = $data['id'];
		array_shift($data);
		 $re = DB::table('help') ->where('id', $id)->update($data);
		 if($re){
			return redirect("help/index");
		 }else{
			 return back()->with('store_error','操作失败');
		 }
	}

	//意见反馈
	public function feedback(){
		$data = DB::table("feedback")->orderBy("status","asc")->orderBy("id","desc")->get();
		//dd($data);
		return view("help.feedback",["list"=>$data]);
	}
	public function feedDel(Request $request){
		$id = $request->input("id");
		$re = DB::table("feedback")->where("id",$id)->delete();
		if($re){
			return redirect("help/feedback");
		}else{
			return false;
		}
	}
	//反馈更新
	public function feedUpdate(Request $request){
		$id = $request->input("id");
		$re = DB::table("feedback")->where("id",$id)->update(["status"=>1]);
		if($re){

			return redirect("help/feedback");
		}else{
			return false;
		}
	}

}
